<template>
  <div id="pieChart" :class="className" :style="{height:height,width:width}" />
</template>

<script>
import * as echarts from 'echarts'
require('echarts/theme/macarons') // echarts theme
import { req } from '@/api/pie'
export default {
  props: {
    className: {
      type: String,
      default: 'chart'
    },
    width: {
      type: String,
      default: '100%'
    },
    height: {
      type: String,
      default: '500px'
    }
  },
  data() {
    return {
      chart: null,
      values: null
    }
  },
  mounted() {
    req().then(
      response => {
        this.values = response.object
        console.log(this.values)
        this.initChart()
      }
    )
  },
  methods: {
    initChart() {
      this.chart = echarts.init(document.getElementById('pieChart'), 'macarons')

      this.chart.setOption({
        title: {
          show: true,
          text: '总体预约一览'
        },
        tooltip: {
          trigger: 'item',
          formatter: '{a} <br/>{b} : {c} ({d}%)',
          textStyle: {
            color: '#fff'
          }
        },
        legend: {
          left: 'center',
          bottom: '10',
          data: ['医生已拒绝', '患者已拒绝', '待医生确认', '待患者确认', '确认未履行', '确认已履行']
        },
        series: [
          {
            name: '预约情况一览',
            type: 'pie',
            minShowLabelAngle: '5',
            radius: [100, 150],
            center: ['50%', '38%'],
            data: [
              { value: this.values.doctorReject, name: '医生已拒绝', itemStyle: { color: '#000' }},
              { value: this.values.patientReject, name: '患者已拒绝' },
              { value: this.values.doctorNotAgr, name: '待医生确认' },
              { value: this.values.patientNotAgr, name: '待患者确认' },
              { value: this.values.agreeNotCon, name: '确认未履行' },
              { value: this.values.agreeCon, name: '确认已履行' }
            ],
            animationEasing: 'cubicInOut',
            animationDuration: 2600
          }
        ]
      })
    }
  }
}
</script>
